<script setup lang="ts">

import {useRouter} from "vue-router";
import {onMounted, ref} from "vue";
import {getCurrentUser} from "../services/user.ts";

// const user = {
//   id: 1,
//   username: 'dogyupi',
//   userAccount: 'dogyupi',
//   avatarUrl: 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2Fb4a87154-18b6-4163-ac80-f4dc4bf58d09%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1700927777&t=9ac00d593319124f94893c1e8f90864d',
//   gender: '男',
//   phone: '123123131',
//   email: '123@qq.com',
//   planetCode: '123',
//   createTime: new Date(),
// }
const user = ref();

onMounted( async () =>{
  user.value = await getCurrentUser();
})

const router = useRouter();

const toEdit = (editKey: string,editName: string,currentValue: string) => {
  console.log(editKey);
  router.push({
    path: '/user/edit',
    query: {
      editKey,
      editName,
      currentValue,
    }
  })
}
</script>

<template>
  <template v-if="user">
  <van-cell title="昵称" is-link to="/user/edit" :value="user.username" @click="toEdit('username','昵称',user.username)"/>
  <van-cell title="账号" :value="user.userAccount" />
  <van-cell title="头像" is-link to="/user/edit" @click="toEdit('avatarUrl','头像',user.avatarUrl)">
    <img style="height: 36px" :src="user.avatarUrl" />
  </van-cell>
  <van-cell title="性别" is-link :value="user.gender" @click="toEdit('gender','性别',user.gender)" />
  <van-cell title="电话" is-link to="user/edit" :value="user.phone" @click="toEdit('phone','电话',user.phone)" />
  <van-cell title="邮箱" is-link to="user/edit" :value="user.email" @click="toEdit('email','邮箱',user.email)"/>
  <van-cell title="星球编号" :value="user.planetCode" />
  <van-cell title="注册时间" :value="user.createTime" />
  </template>
</template>

<style scoped>

</style>